#ifndef UTILITY_H
#define UTILITY_H

#include <sstream>
#include <time.h> 
#include <vector>

namespace Engine
{

inline void ParseFileName(const char* source, char* dest)
{
	int j = 0;
	char character;
	for(unsigned int i = 0; i < strlen(source);i++)
	{
		character = source[i];
		if(character == '\\')
		{
			dest[0] = NULL;
			j = 0;
		}
		else
		{
			dest[j] = character;
			j++;
		}
	}
	dest[j] = 0;
}

inline double cint(double x)
{
	double intpart;
	if (modf(x,&intpart) >= .5)
		return x>=0?ceil(x):floor(x);
	else
		return x<0?ceil(x):floor(x);
}

inline double round(double r, unsigned places)
{
	if(r == 0)return 0;
	double off=pow(10,places);
	return cint(r*off)/off;
}

inline std::string IntToString(int value)
{
	std::stringstream stringStream;
	stringStream << value;
	return stringStream.str().c_str();
}

inline std::string FloatToString(float value)
{
	std::stringstream stringStream;
	stringStream << value;
	return stringStream.str().c_str();
}

inline int GetRandomInt(int max)
{
	srand ( (unsigned int) time(NULL) );
	
	int randomValue = rand() % max;

	return randomValue;
}

inline float GetRandomFloat(int max)
{
	srand ( (unsigned int) time(NULL) );
	
	float randomValue = (float)(rand() % max);

	return randomValue;
}

inline std::vector<std::string>& split(const std::string &s, char delim, std::vector<std::string> &elems) 
{
    std::stringstream ss(s);
    std::string item;
    while (std::getline(ss, item, delim)) {
        elems.push_back(item);
    }
    return elems;
}

inline std::vector<std::string> split(const std::string &s, char delim) 
{
    std::vector<std::string> elems;
    split(s, delim, elems);
    return elems;
}

}
#endif